package scc.project.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import scc.project.dao.GoodsDao;
import scc.project.entity.Goods;
import scc.project.entity.vo.PageVo;

import java.util.List;

/**
 * @author 陈圳佳
 *         日期：2015/6/22
 */
@Service
public class GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    public PageVo<Goods> find(Integer page, String goodsName, String supplier) {
        PageVo<Goods> pageVo = new PageVo<Goods>(page);
        List<Goods> shops = goodsDao.find(pageVo.getOffset(), page, goodsName, supplier);
        Long total = goodsDao.findTotal(goodsName, supplier);
        pageVo.addParam("goodsName", goodsName).addParam("supplier", supplier);
        pageVo.setData(shops).setTotal(total);
        return pageVo;
    }

    public Goods get(Long id) {
        return goodsDao.selectById(id);
    }


    public List<Goods> getAll() {
        return goodsDao.selectAll();
    }

    public Goods getByName(String name) {
        return goodsDao.getByName(name);
    }
}
